<?php

/**
 * @Author: Bing
 * @Date:   2019-04-14 22:07:46
 * @Email:  huangfreeze@gmail.com
 * @Last Modified time: 2019-04-30 17:27:33
 */

/**
 * 微信回调
 */
class Wechat extends IController
{
	public function callBack() {

		$userModel = WechatMp::getUserService();
		$info = $userModel->getOriginal();

		$openid = ArrayHelper::getValue($info, 'openid');
		if ( !$openid ) {
			IError::show('404');
		}

		$login = WechatMp::wechatAutoLogin($info);
		if ( !$login ) {
			IError::show('404');
		}
		
		$url = plugin::trigger('getCallback');
		if ( !$url ) {
			$url = '/site/index';
		}
		$this->redirect($url);
		exit;
	}
}
